#ifndef CAMERA_H
#define CAMERA_H

#include <QObject>
#include <QThread>
#include <atomic>
#include <opencv4/opencv2/opencv.hpp>
#include <QMetaType>

//namespace cv {
// qRegisterMetaType<Mat>("Mat");
//}


class Camera : public QThread
{
    Q_OBJECT
public:
    explicit Camera(QObject *parent = nullptr);

    bool openCamea(const QString &device_name);

    // 停止相机画面帧抓取，线程也将停止
    void stop();
protected:
    void run() override;

private:

    void start_capture();
    void stop_capture();
    void capture();

signals:
    // 发送图像帧
    void appending_frame(cv::Mat);

private:
    std::atomic_bool m_loop{false};
    cv::VideoCapture* m_video_capturer{nullptr};

    // 帧率
    quint32 fps{0};
};

#endif // CAMERA_H
